import SDKManager from "../../../sdk/SDKManager";
import RandomHelper from "../../../cfw/tools/RandomHelper";
import GameItemModel from "../../../sdk/base/GameItemModel";

// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class BigContineButton extends cc.Component {


    @property(cc.Label)
    label: cc.Label = null;

    @property({
        type: cc.Component.EventHandler,
        displayName: "回调函数"
    })
    callback = new cc.Component.EventHandler();

    protected state: number = 0;

    start() {
        // this.node.on(cc.Node.EventType.TOUCH_END, this.touchEnd, this)
        let random = SDKManager.getChannel().getRandom_jump()
        if (random) {
            this.label.string = '随机一个'
            this.state = 1;
            cc.tween(this.node).delay(3)
                .call(() => {
                    this.state = 2;
                    this.label.string = '继续游戏'
                })
                .start();
        }

    }

    onBackClick() {
        if (this.state == 0 || this.state == 2) {
            this.callback.emit([])
        } else {
            let list = SDKManager.getChannel().getAdData();
            if (list) {
                let model: GameItemModel = list[RandomHelper.random(0, list.length)]
                if (model) {
                    SDKManager.getChannel().navigate2Mini(model)
                }
            }
            this.state = 2;
            this.label.string = '继续游戏'
        }
    }

    // update (dt) {}
}
